<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>更新班级</title>
    <link th:href="@{~/assets/layui/css/layui.css}" rel="stylesheet"/>
</head>
<body style="margin: 10px">
<fieldset class="layui-elem-field">
    <legend>专业</legend>
    <form class="layui-form" method="post">
    <div class="layui-input-inline">
        <div class="layui-form-item">
            <select name="majorinfo" id="majorinfo"  >
                <option value=""> 请选择 </option>
                <option th:selected="${classroom.majorId eq option.id}"
                        th:each="option : ${major}"
                        th:value="${option.id}" th:text="${option.name}"></option>

            </select>
        </div>
    </div></form>
</fieldset>
<fieldset class="layui-elem-field">
    <legend>班级</legend>
    <input type="text" name="classroom" id="classroom" class="layui-input" placeholder="班级"  th:value="${classroom.className}">
    <input type="text" name="id" id="id" style="display: none" th:value="${classroom.id}">
</fieldset>


<hr>
<div class="layui-input-inline">
    <div class="layui-form-item">
        <button type="button" class="layui-btn" id="push">提交</button>
    </div>
</div>

</body>
<script th:src="@{~/assets/layui/layui.js}"></script>
<script th:src="@{~/assets/jquery.min.js}"></script>
<script>


    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;


    });


    $("#push").click(function () {

        var name = $("#classroom").val()
        var majorId = $("#majorinfo").val()
        var id = $("#id").val()

        $.ajax({
            type: "post",
            contentType: "application/x-www-form-urlencoded",
            url: "/api/v1/classroom/update",
            data: {
                "id":id,
                "majorId":majorId,
                "className":name
            },
            dataType: "json",
            success: function (data) {
                if (data.resultTypeEnum == 200) {
                    layer.msg("操作成功", {
                        icon: 1
                    });
                    var index = parent.layer.getFrameIndex(window.name);

                    parent.layui.table.reload('test');
                    //关闭父级页面的表格
                }else {
                    layer.msg(data.message, {
                        icon: 5
                    });
                }
            }
        });
    })
</script>
</html>